package com.airsystem.pos.bengkel.service.parser;

import org.apache.log4j.Logger;

import com.airsystem.pos.bengkel.entity.JenisTagihan;
import com.airsystem.pos.bengkel.entity.Tagihan;
import com.airsystem.pos.bengkel.interfaces.IParser;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class TagihanParser implements IParser<Tagihan, Object> {
	private static final Logger LOG = Logger.getLogger(TagihanParser.class.getSimpleName());

	public Tagihan doParse(Object data) {
		Tagihan tagihan = null;
		Object[] objects = (Object[]) data;

		for (Object item : objects) {
			if (isTagihanInstance(item)) {
				tagihan = (Tagihan) item;
			} else if (isJenisTagihanInstance(item)) {
				tagihan.setJenis_tagihan((JenisTagihan) item);
			} else {
				LOG.info("Instance result is " + item.toString());
			}

			continue;
		}

		return tagihan;
	}

	private boolean isTagihanInstance(Object object) {
		return (object instanceof Tagihan);
	}

	private boolean isJenisTagihanInstance(Object object) {
		return (object instanceof JenisTagihan);
	}
}